package com.label.Web;

import com.label.Config.Logger.LogAnnotation;
import com.label.Model.Common.ResponseBean;
import com.label.Model.Query.ProfileDisQuery;
import com.label.Model.Vo.ProfileDisVo;
import com.label.Service.Impl.ProfilesDisServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.POST;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "责任画像")
@RequestMapping(value = "/profile")
public class ProfilesDisController {

    @Autowired
    ProfilesDisServiceImpl profilesDisService;


    @PostMapping("/getTeacherList")
    @LogAnnotation(module = "获取老师角色和画报", operator = "获取老师角色和画报信息")
    // @RequiresAuthentication
    @ApiOperation(value = "获取老师角色和画报信息")
    public ResponseBean selectAllProfileSDis(@RequestBody @ApiParam(value = "老师责任画报信息") ProfileDisQuery profileDisQuery) {
        List<ProfileDisVo> list = profilesDisService.selectAllProfileSDis(profileDisQuery);

        return new ResponseBean(200, "成功", list);
    }

    @GetMapping("/getTeacherRole")
    @LogAnnotation(module = "获取老师角色", operator = "获取老师角色")
    @RequiresAuthentication
    @ApiOperation(value = "获取老师角色")
    public ResponseBean getAllRole(@Param("accountId") @ApiParam(value = "教师账户") String accountId) {
        List<Map<String, Object>> list = profilesDisService.getAllRole(accountId);

        return new ResponseBean(200, "成功", list);
    }

    @GetMapping("/getProfiles")
    @LogAnnotation(module = "获取角色下画像", operator = "获取角色下画像")
    //  @RequiresAuthentication
    @ApiOperation(value = "获取角色下画像")
    public ResponseBean getAllProfiles(@Param(value = "accountId") @ApiParam(value = "教师账户") String accountId, @Param(value = "roleId") @ApiParam(value = "角色id") String roleId) {
        List<Map<String, String>> list = profilesDisService.getAllProfiles(accountId, roleId);

        return new ResponseBean(200, "成功", list);
    }

    @GetMapping("/getUnusedProfiles")
    @LogAnnotation(module = "获取角色未使用的画像", operator = "获取角色下画报")
    //   @RequiresAuthentication
    @ApiOperation(value = "获取角色未使用画报")
    public ResponseBean getUnusedProfiles(@Param(value = "accountId") @ApiParam(value = "教师账户") String accountId,
                                          @Param(value = "roleId") @ApiParam(value = "角色id") String roleId,
                                          @Param(value = "profileId") @ApiParam(value = "画像id") String profileId) {
        List<Map<String, String>> list = profilesDisService.getUnusedProfiles(accountId, roleId, profileId);
        return new ResponseBean(200, "成功", list);
    }

    @GetMapping("/delProfile")
    @LogAnnotation(module = "删除画像", operator = "删除角色下画报")
    // @RequiresAuthentication
    @ApiOperation(value = "删除角色画像")
    public ResponseBean delProfile(@Param(value = "accountId") @ApiParam(value = "教师账户") String accountId,
                                   @Param(value = "roleId") @ApiParam(value = "角色id") String roleId,
                                   @Param(value = "profileId") @ApiParam(value = "画像id") String profileId) {
        Boolean flag = profilesDisService.delProfile(accountId, roleId, profileId);
        return new ResponseBean(200, "成功", flag);
    }

    @GetMapping("/insertProfile")
    @LogAnnotation(module = "插入画像", operator = "插入画报")
    @RequiresAuthentication
    @ApiOperation(value = "插入角色画像")
    public ResponseBean insertProfile(@Param(value = "accountId") @ApiParam(value = "教师账户") String accountId,
                                      @Param(value = "roleId") @ApiParam(value = "角色id") String roleId,
                                      @Param(value = "profileId") @ApiParam(value = "画像id") String profileId) {
        Boolean flag = profilesDisService.insertProfile(accountId, roleId, profileId);
        return new ResponseBean(200, "成功", flag);
    }


}
